<template>
	<view class="content">
		<view class="tabs">
			<view class="tab" @tap="changeSwiper(index)" :class="{active:tab_index == index}" v-for="(item,index) in tabs" :key="index">{{item}}</view>
		</view>
		<view>
			
		</view>
		<!-- <swiper :current="tab_index" @change="swiperChange" disable-touch="true"> -->
			<!-- 待接收 -->
			<view v-if="tab_index == 0">
				<view class="swiper-item">
					<view class="item" v-for="(item,index) in list" :key="index">
						<view class="title">{{item.project_name}}</view>
						<view class="type">项目类型：{{item.cate_name}}</view>
						<view class="type">服务项目：{{item.cate_names}}</view>
						<view class="type">亩数：{{item.number}}亩</view>
						<view class="name">申请人信息</view>
						<view class="info">{{item.contactor}}：{{item.contactor_phone}}</view>
						<view class="info">{{item.address}}</view>
						<view class="time">
							<view>
								<view>申请时间：</view>
								<text>{{item.createtime_text}}</text>
							</view>
							<view class="btn" @click="changeStatus(item.id,'2')">接受任务</view>
						</view>
						<!-- <view class="time">服务人员：啊啊啊</view> -->
					</view>
				</view>
			</view>
			<!-- 进行中 -->
			<view  v-if="tab_index == 1">
				<view class="swiper-item" v-for="(item,index) in list" :key="index">
					<view class="item">
						<view class="title">{{item.project_name}}</view>
						<view class="type">项目类型：{{item.cate_name}}</view>
						<view class="type">服务项目：{{item.cate_names}}</view>
						<view class="type">亩数：{{item.number}}亩</view>
						<view class="name">申请人信息</view>
						<view class="info">{{item.contactor}}：{{item.contactor_phone}}</view>
						<view class="info">{{item.address}}</view>
						<view class="time">
							<view>
								<view>申请时间：</view>
								<text>{{item.createtime_text}}</text>
							</view>
							<view class="btn" @click="changeStatus(item.id,'3')">完成任务</view>
						</view>
					</view>
				</view>
			</view>
			<!-- 已完成 -->
			<view  v-if="tab_index == 2">
				<view class="swiper-item">
					<view class="item" v-for="(item,index) in list" :key="index">
						<view class="title">{{item.project_name}}</view>
						<view class="type">项目类型：{{item.cate_name}}</view>
						<view class="type">服务项目：{{item.cate_names}}</view>
						<view class="type">亩数：{{item.number}}亩</view>
						<view class="name">申请人信息</view>
						<view class="info">{{item.contactor}}：{{item.contactor_phone}}</view>
						<view class="info">{{item.address}}</view>
						<view class="time">申请时间：{{item.createtime_text}}</view>
						<!-- <view class="time">完成时间：{{item.complete_time}}</view> -->
					</view>
				</view>
			</view>
		<!-- </swiper> -->
    <view  v-if="tab_index == 3">
    	<view class="swiper-item">
    		<view class="item" v-for="(item,index) in list" :key="index">
    			<view class="title">{{item.project_name}}</view>
    			<view class="type">项目类型：{{item.cate_name}}</view>
    			<view class="type">服务项目：{{item.cate_names}}</view>
    			<view class="type">亩数：{{item.number}}亩</view>
    			<view class="name">申请人信息</view>
    			<view class="info">{{item.contactor}}：{{item.contactor_phone}}</view>
    			<view class="info">{{item.address}}</view>
    			<view class="time">申请时间：{{item.createtime_text}}</view>
    			<view class="time">完成时间：{{item.pay_time}}</view>
    		</view>
    	</view>
    </view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				tabs:['待接收','进行中','待确认','已完成'],
				tab_index:0,
				page: 1,
				last_page: 1,
				list: []
			}
		},
		onReachBottom() {
			if(this.last_page - this.page >= 0){
				this.loadData();
				this.page ++
			}
		},
		onLoad(options) {
			uni.setNavigationBarTitle({
			    title: options.title
			});
			this.tab_index = options.index;
		},
		onShow() {
			this.loadData()
		},
		methods: {
			//接受完成任务
			changeStatus(id,status){
				this.$http.post('/api/order/update',{status,id}).then(res => {
					this.page=1
					this.loadData()
				})
			},
			changeSwiper(index){
				this.page = 1;
				this.tab_index = index;
				this.loadData()
			},
			loadData(){
				this.$http.post('/api/order/serveindex',{
					status: parseInt(this.tab_index) + 1,
					limit:3,
					page: this.page,
				}).then(res => {
					console.log(res)
					this.last_page = res.data.data.last_page;
					if(this.page == 1){
						this.list = res.data.data.data;
						this.page = 2
					}else{
						 this.list = this.list.concat(res.data.data.data)
					}
				})
			},
			stopTouchMove(e){
				return false;
			}
		}
	}
</script>

<style lang="scss" scoped>
.content{
	// min-height: 100vh;
	background-color: #F8F8F8;
	padding: 5rpx 30rpx 80rpx;
	box-sizing: border-box;
}
.tabs{
	display: flex;
	justify-content: flex-start;
	align-items: center;
	padding: 30rpx 0rpx;
	box-sizing: border-box;
	.tab{
		font-size:15px;
		font-family:PingFang SC;
		font-weight:500;
		color:rgba(51,51,51,1);
		margin-right: 40rpx;
		&.active{
			font-size:20px;
			font-family:PingFang SC;
			font-weight:bold;
			color:rgba(63,195,119,1);
		}
	}
}
// swiper{
// 	height: calc(100vh - 116rpx);
// 	overflow: scroll;
// }
.swiper-item{
	// height: calc(100vh - 116rpx);
	overflow: scroll;
}
.item{
	padding: 30rpx;
	box-sizing: border-box;
	width: 690rpx;
	background:rgba(255,255,255,1);
	border-radius:20px;
	margin-bottom: 30rpx;
	// height: 540rpx;
	.title{
		font-size:17px;
		font-family:PingFang SC;
		font-weight:bold;
		color:rgba(51,51,51,1);
	}
	.type{
		font-size:15px;
		font-family:PingFang SC;
		font-weight:500;
		color:rgba(51,51,51,1);
		margin-top: 29rpx;
	}
	.name{
		font-size:17px;
		font-family:PingFang SC;
		font-weight:bold;
		color:rgba(51,51,51,1);
		margin-top: 50rpx;
	}
	.info{
		font-size:16px;
		font-family:PingFang SC;
		font-weight:500;
		color:rgba(51,51,51,1);
		margin-top: 28rpx;
	}
	.time{
		font-size:17px;
		font-family:PingFang SC;
		font-weight:bold;
		color:rgba(63,195,119,1);
		margin-top: 43rpx;
		display: flex;
		justify-content: space-between;
		align-items: center;
		.btn{
			width:160rpx;
			height:60rpx;
			background:rgba(2,213,144,1);
			border-radius:10px;
			line-height: 60rpx;
			text-align: center;
			font-size:13px;
			font-family:PingFang SC;
			font-weight:500;
			color:rgba(255,255,255,1);
		}
	}
}
</style>
